/**
 * Created by huachuan on 2016/1/11.
 */
angular.module('meattendcontrollers', [])
//登录的Controller
  .controller('MeAttendCtrl', function($scope,$state,$ionicPopup,$timeout,ENV,MeAttend,Loading,Toast,Storage,History){
      //获取会员编号
      var memberId = '';
      $scope.picPath = ENV.picPath;
      //是否显示取消关注提示框
      $scope.showConfirm = false;
    $scope.$on('$ionicView.beforeEnter',function() {
      memberId = Storage.get("member").member_id;
      //获取关注列表
      MeAttend.getMeAttentionList(memberId);
    });
    //关注会员
    $scope.foucsMember = function(toAttendMemberId){
     // console.log(toAttendMemberId);
      //如果在显示查找的时候
      Loading.showLoading();
      MeAttend.focusFriend(memberId,toAttendMemberId);
    }
    //取消关注
    //var saveNoAttendMemberId = '';
    $scope.noFoucsMember = function(noAttendMemberId){
      $ionicPopup.confirm({
        template: '<p style="text-align: center;font-size:16px">确定要取消关注吗？</p>',
        cancelText: '继续关注',
        okText: '取消关注',
        okType: 'hd-red-btn',
        cancelType: 'cancel-esc-btn'
      }).then(function (res) {
        if (res) {
          //取消对该会员的关注
          Loading.showLoading();
          MeAttend.focusFriend(memberId,noAttendMemberId);
        }
      });
     /* saveNoAttendMemberId = noAttendMemberId;
      $scope.showConfirm = true;*/
    }
   /* //继续关注
    $scope.cancel = function(){
      saveNoAttendMemberId = '';
      $scope.showConfirm = false;
    }
    //取消关注
    $scope.confirmNoAttend = function(){
      //如果在显示查找的时候
      $scope.showConfirm = false;
      MeAttend.focusFriend(memberId,saveNoAttendMemberId);
      saveNoAttendMemberId = '';
    }*/
    //关注或者取消关注时访问网络成功返回的信息
    $scope.$on('MeAttend.focusFriendUpdated',function(){
      Loading.hideLoading();
      var result = MeAttend.getFocusFriendMsgJson();
      if(result.isAttendMsg!='网络异常，请稍后再试'){
        //重新获取关注列表获取关注列表
        MeAttend.getMeAttentionList(memberId);
      }
      Toast.showMessage(result.isAttendMsg);
    });

      $scope.$on('MeAttend.meAttentionListUpdated',function(){
        $scope.attendMemberList = MeAttend.getMeAttentionListJson();
      });
    //点击用户头像是的操作
    $scope.go2OtherHome  = function(otherMemberId){
      if(memberId==otherMemberId){
        $state.transitionTo("tab.meIndex");
      }else{
        $state.transitionTo("user-dimple-care-list",{memberId:otherMemberId});
      }
    }
    //返回
    $scope.goback = function(){
      History.goback();
    }
  })
